#include "BitmapDraw.h"

BitmapDraw::BitmapDraw(ALLEGRO_FONT* font18, ALLEGRO_FONT* font36, ALLEGRO_FONT* font144 ):

    _MainImage(0),
    _DigDugImage(0),
    _SoilImage(0),
    _RedMonsterImage(0),
    _DisembodiedRedMonster(0),
    _ArrowImage(0),
    _font18(font18),
    _font36(font36),
    _font144(font144)
{

}

void BitmapDraw::DrawAllBitmaps()
{
    DrawMainImage();
    DrawDigDugBitmap();
    DrawSoilBitmap();
    DrawRedMonsterBitmap();
    DrawDisembodiedRedMonsterBitmap();
    DrawArrowBitmap();

    DrawTitleBitmap();
    DrawLevelPassBitmap();
    DrawGameOver();
}

void BitmapDraw::DrawMainImage()
{
    _MainImage = al_create_bitmap(1300, 700);
}

void BitmapDraw::DrawDigDugBitmap()
{
    _DigDugImage = al_create_bitmap(50, 50);
    al_set_target_bitmap(_DigDugImage);

    al_clear_to_color(al_map_rgb(0,0,0));

    al_hold_bitmap_drawing(true);

    al_draw_filled_circle(20,20,18,al_map_rgb(50,50,255));            //head
    al_draw_line(20,36,34,42,al_map_rgb(0,255,255),3);                //leg
    al_draw_line(34,42,38,50,al_map_rgb(0,0,255),3);                //leg
    al_draw_line(38,50,42,49,al_map_rgb(0,0,255),3);                //foot
    al_draw_line(20,36,16,45,al_map_rgb(0,255,255),3);                //leg
    al_draw_line(16,45,10,44,al_map_rgb(0,0,255),3);                //leg
    al_draw_line(10,44,8,48,al_map_rgb(0,0,255),3);                //leg
    al_draw_arc(20,20,9,-0.5,-4,al_map_rgb(255,255,255),22);     //helmet
    al_draw_arc(20,20,12,-0,-0.5,al_map_rgb(200,200,200),23);     //helmet visor
    al_draw_filled_circle(19,19,9,al_map_rgb(165,70,165));
    al_draw_filled_circle(19,19,4,al_map_rgb(255,255,255));
    al_draw_arc(20,20,16,-1,-3,al_map_rgb(150,70,150),2);
    al_draw_filled_circle(30,24,3,al_map_rgb(0,0,0));               //eye
    al_draw_filled_circle(30,24,1,al_map_rgb(200,255,255));               //eyeball
    al_draw_line(20,36,48,36,al_map_rgb(150,150,150),4);
    al_draw_line(29,32,42,32,al_map_rgb(150,150,150),2);
    al_draw_filled_triangle( 46,38,44,38,45,42,al_map_rgb(150,150,150));
    al_draw_filled_triangle( 20,36,36,36,20,42,al_map_rgb(150,150,150));

    al_hold_bitmap_drawing(false);

}

void BitmapDraw::DrawSoilBitmap()
{
    _SoilImage = al_create_bitmap( 1300, 600);
    al_set_target_bitmap(_SoilImage);

    al_hold_bitmap_drawing(true);

    al_draw_filled_rectangle(0,0, 1300, 150, al_map_rgb(255,255,0));
    al_draw_filled_rectangle(0,150, 1300, 300, al_map_rgb(255,155,0));
    al_draw_filled_rectangle(0,300, 1300, 450, al_map_rgb(255,55,0));
    al_draw_filled_rectangle(0,450, 1300, 600, al_map_rgb(255,0,0));

    al_draw_filled_rectangle(150, 400, 450, 450, al_map_rgb(0,0,0));    //starting tunnels
    al_draw_filled_rectangle(950, 100, 1200, 150, al_map_rgb(0,0,0));
    al_draw_filled_rectangle(850, 300, 900, 550, al_map_rgb(0,0,0));
    al_draw_filled_rectangle(200, 50, 250, 250, al_map_rgb(0,0,0));

    al_hold_bitmap_drawing(false);
}

void BitmapDraw::DrawRedMonsterBitmap()
{
    _RedMonsterImage = al_create_bitmap(50,50);
    al_set_target_bitmap(_RedMonsterImage);

    al_hold_bitmap_drawing(true);

    al_draw_filled_circle(30,30,20,al_map_rgb(255,0,0));
    al_draw_rounded_rectangle(20,20,47,30,3,3,al_map_rgb(255,255,0),4);
    al_draw_line(20,22,10,21,al_map_rgb(255,255,0),4);
    al_draw_filled_rounded_rectangle(21,21,45,28,3,3,al_map_rgb(255,255,255));
    al_draw_filled_rectangle(28,22,30,26,al_map_rgb(0,0,0));
    al_draw_filled_rectangle(37,22,39,26,al_map_rgb(0,0,0));
    al_draw_line(20,49,20,50,al_map_rgb(255,255,0),5);
    al_draw_line(40,49,40,50,al_map_rgb(255,255,0),5);

    al_hold_bitmap_drawing(false);
}

void BitmapDraw::DrawDisembodiedRedMonsterBitmap()
{
    _DisembodiedRedMonster = al_create_bitmap(50,50);
    al_set_target_bitmap(_DisembodiedRedMonster);

    al_hold_bitmap_drawing(true);

    al_draw_rounded_rectangle(20,20,47,30,3,3,al_map_rgb(0,100,255),4);
    al_draw_line(20,22,10,21,al_map_rgb(0,100,255),4);
    al_draw_filled_rounded_rectangle(21,21,45,28,3,3,al_map_rgb(255,255,255));
    al_draw_filled_rectangle(28,22,30,26,al_map_rgb(0,0,0));
    al_draw_filled_rectangle(37,22,39,26,al_map_rgb(0,0,0));

    al_hold_bitmap_drawing(false);
}

void BitmapDraw::DrawArrowBitmap()
{
    _ArrowImage = al_create_bitmap(150, 50);
}

void BitmapDraw::DrawTitleBitmap()
{
    _TitleImage = al_create_bitmap(1300, 700);

    al_set_target_bitmap(_TitleImage);
    al_clear_to_color(al_map_rgb(0,0,255));

    al_hold_bitmap_drawing(true);

    al_draw_text(_font144, al_map_rgb(0,0,0), 1300/2, 250, ALLEGRO_ALIGN_CENTRE, "DIG DUG");
    al_draw_text(_font36, al_map_rgb(0,0,0), 1300/2, 450, ALLEGRO_ALIGN_CENTRE, "press space bar to begin");

    al_hold_bitmap_drawing(false);
}

void BitmapDraw::DrawLevelPassBitmap()
{
    _LevelPassImage = al_create_bitmap(1300, 700);

    al_set_target_bitmap(_LevelPassImage);
    al_clear_to_color(al_map_rgb(0,255,0));

    al_hold_bitmap_drawing(true);

    al_draw_text(_font144, al_map_rgb(0,0,0), 1300/2, 120, ALLEGRO_ALIGN_CENTRE, "LEVEL");
    al_draw_text(_font144, al_map_rgb(0,0,0), 1300/2, 250, ALLEGRO_ALIGN_CENTRE, "COMPLETED");
    al_draw_text(_font36, al_map_rgb(0,0,0), 1300/2, 450, ALLEGRO_ALIGN_CENTRE, "press space bar to continue");

    al_hold_bitmap_drawing(false);
}

void BitmapDraw::DrawGameOver()
{
    _GameOverImage = al_create_bitmap(1300, 700);

    al_set_target_bitmap(_GameOverImage);
    al_clear_to_color(al_map_rgb(255,0,0));


    al_hold_bitmap_drawing(true);

    al_draw_text(_font144, al_map_rgb(0,0,0), 1300/2, 250, ALLEGRO_ALIGN_CENTRE, "GAME OVER");
    al_draw_text(_font36, al_map_rgb(0,0,0), 1300/2, 450, ALLEGRO_ALIGN_CENTRE, "press space bar to try again");

    al_hold_bitmap_drawing(false);
}

void BitmapDraw::reinit_SoilImage()
{
    al_set_target_bitmap(_SoilImage);

    al_hold_bitmap_drawing(true);

    al_draw_filled_rectangle(0,0, 1300, 150, al_map_rgb(255,255,0));
    al_draw_filled_rectangle(0,150, 1300, 300, al_map_rgb(255,155,0));
    al_draw_filled_rectangle(0,300, 1300, 450, al_map_rgb(255,55,0));
    al_draw_filled_rectangle(0,450, 1300, 600, al_map_rgb(255,0,0));

    al_draw_filled_rectangle(150, 400, 450, 450, al_map_rgb(0,0,0));    //starting tunnels
    al_draw_filled_rectangle(950, 100, 1200, 150, al_map_rgb(0,0,0));
    al_draw_filled_rectangle(850, 300, 900, 550, al_map_rgb(0,0,0));
    al_draw_filled_rectangle(200, 50, 250, 250, al_map_rgb(0,0,0));

    al_hold_bitmap_drawing(false);
}

ALLEGRO_BITMAP* BitmapDraw::get_MainImage(){return _MainImage;}

ALLEGRO_BITMAP* BitmapDraw::get_DigDugImage(){return _DigDugImage;}

ALLEGRO_BITMAP* BitmapDraw::get_SoilImage(){return _SoilImage;}

ALLEGRO_BITMAP* BitmapDraw::get_RedMonsterImage(){return _RedMonsterImage;}

ALLEGRO_BITMAP* BitmapDraw::get_DisembodiedRedMonsterImage(){return _DisembodiedRedMonster;}

ALLEGRO_BITMAP* BitmapDraw::get_ArrowImage(){return _ArrowImage;}

ALLEGRO_BITMAP* BitmapDraw::get_TitleImage(){return _TitleImage;}

ALLEGRO_BITMAP* BitmapDraw::get_LevelPassImage(){return _LevelPassImage;}

ALLEGRO_BITMAP* BitmapDraw::get_GameOverImage(){return _GameOverImage;}

BitmapDraw::~BitmapDraw()
{


    al_destroy_bitmap(_DigDugImage);
    al_destroy_bitmap(_SoilImage);
    al_destroy_bitmap(_RedMonsterImage);
    al_destroy_bitmap(_DisembodiedRedMonster);
    al_destroy_bitmap(_ArrowImage);
    al_destroy_bitmap(_TitleImage);
    al_destroy_bitmap(_LevelPassImage);
    al_destroy_bitmap(_GameOverImage);


}
